import { Conf } from './util/Conf';
import { Log } from './util/Log';
import { GlobalData } from './global/GlobalData';
import { ServerInfo } from './struct/ServerInfo';
import { SocketManager } from './manager/SocketManager';

function main(args:Array<string>):void
{
    if(args.length > 2)//处理启动参数
    {
        
    }
    Log.init();
    entr.init(args);
}


class Entrance
{
    constructor()
    {

    }

    public init(args):void
    {
        //1.解析启动参数

        //2.读取配置
        let obj = Conf.read();JSON.parse
        Log.log(obj.ip);
        this.parseConfig(obj);

        //3.服务初始化
        SocketManager.getInstance().init();
    }

    private parseConfig(obj:any):void
    {
        GlobalData.selfInfo = new ServerInfo();
        GlobalData.selfInfo.ip = obj.ip;
        GlobalData.selfInfo.port = obj.port;
        GlobalData.selfInfo.version = obj.version;

        GlobalData.accInfo = new ServerInfo();
        GlobalData.accInfo.ip = obj.acc.ip;
        GlobalData.accInfo.port = obj.acc.port;
        GlobalData.accInfo.version = obj.acc.version;

        GlobalData.dbInfo = new ServerInfo();
        GlobalData.dbInfo.ip = obj.db.ip;
        GlobalData.dbInfo.port = obj.db.port;
        GlobalData.dbInfo.version = obj.db.version;
    }
}


var entr = new Entrance();
main(process.argv);